home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / sys / amiga / src / pla_iff.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-23  |  5.6 KB  |  219 lines

  1. /* $Id: pla_iff.c,v 1.4 1994/03/23 08:56:06 mjl Exp $
  2.    $Log: pla_iff.c,v $
  3.  * Revision 1.4  1994/03/23  08:56:06  mjl
  4.  * Header file rearrangement, also removed some redundant variable clears.
  5.  *
  6.  * Revision 1.3  1993/07/31  07:56:54  mjl
  7.  * Several driver functions consolidated, for all drivers.  The width and color
  8.  * commands are now part of a more general "state" command.  The text and
  9.  * graph commands used for switching between modes is now handled by the
  10.  * escape function (very few drivers require it).  The device-specific PLDev
  11.  * structure is now malloc'ed for each driver that requires it, and freed when
  12.  * the stream is terminated.
  13.  *
  14.  * Revision 1.2  1993/07/01  21:59:50  mjl
  15.  * Changed all plplot source files to include plplotP.h (private) rather than
  16.  * plplot.h.  Rationalized namespace -- all externally-visible plplot functions
  17.  * now start with "pl"; device driver functions start with "plD_".
  18. */
  19.  
  20. /*    pla_iff.c
  21.  
  22.     PLPLOT Amiga IFF device driver.
  23.     Originally written by Tomas Rokicki (Radical Eye Software).
  24. */
  25.  
  26. #include "plplotP.h"
  27. #include "drivers.h"
  28. #include "plamiga.h"
  29.  
  30. /* top level declarations */
  31.  
  32. static PLINT xsubw, ysubw;
  33. static PLINT vxwidth, vywidth;
  34.  
  35. /* (dev) will get passed in eventually, so this looks weird right now */
  36.  
  37. static PLDev device;
  38. static PLDev (*dev) = &device;
  39.  
  40. /*----------------------------------------------------------------------*\
  41. * plD_init_iff()
  42. *
  43. * Initialize device.
  44. \*----------------------------------------------------------------------*/
  45.  
  46. void 
  47. plD_init_iff(PLStream *pls)
  48. {
  49.     PLDev *dev;
  50.  
  51.     pls->termin = 0;        /* not an interactive terminal */
  52.     pls->icol0 = 1;
  53.     pls->width = 1;
  54.     pls->bytecnt = 0;
  55.     pls->page = 0;
  56.  
  57.     if (!pls->colorset)
  58.         pls->color = 1;
  59.  
  60.     if (!pls->pageset) {
  61.     pls->xdpi    = plGetFlt("Enter desired horizontal resolution (dpi): ");
  62.     pls->ydpi    = plGetFlt("Enter desired vertical   resolution (dpi): ");
  63.     pls->xlength = plGetInt("Enter desired horizontal size in pixels  : ");
  64.     pls->ylength = plGetInt("Enter desired vertical   size in pixels  : ");
  65.     pls->pageset = 1;
  66.     }
  67.  
  68.     vxwidth = pls->xlength * 25;
  69.     vywidth = pls->ylength * 25;
  70.  
  71. /* Allocate and initialize device-specific data */
  72.  
  73.     dev = plAllocDev(pls);
  74.  
  75.     dev->xold = UNDEFINED;
  76.     dev->yold = UNDEFINED;
  77.     dev->xmin = 0;
  78.     dev->xmax = pls->xlength;
  79.     dev->ymin = 0;
  80.     dev->ymax = pls->ylength;
  81.     dev->pxlx = pls->xdpi * 25. / 25.4;
  82.     dev->pxly = pls->ydpi * 25. / 25.4;
  83.  
  84.     plP_setpxl(dev->pxlx, dev->pxly);
  85.     plP_setphy(0, vxwidth, 0, vywidth);
  86.  
  87.     xsubw = pls->xlength - 2;
  88.     ysubw = pls->ylength - 2;
  89.  
  90. /* Allocate bitmap and initialize for line drawing */
  91.  
  92.     if (mapinit(pls->xlength, pls->ylength)) 
  93.     plexit("");
  94. }
  95.  
  96. /*----------------------------------------------------------------------*\
  97. * plD_line_iff()
  98. *
  99. * Draw a line in the current color from (x1,y1) to (x2,y2).
  100. \*----------------------------------------------------------------------*/
  101.  
  102. void 
  103. plD_line_iff(PLStream *pls, short x1a, short y1a, short x2a, short y2a)
  104. {
  105.     PLDev *dev = (PLDev *) pls->dev;
  106.     int x1=x1a, y1=y1a, x2=x2a, y2=y2a;
  107.     long xn1, yn1, xn2, yn2;
  108.  
  109.     xn1 = (x1 * xsubw) / vxwidth;
  110.     yn1 = (y1 * ysubw) / vywidth;
  111.     xn2 = (x2 * xsubw) / vxwidth;
  112.     yn2 = (y2 * ysubw) / vywidth;
  113.  
  114.     switch (pls->width) {
  115.     case 3:
  116.     mapline(xn1, ysubw - yn1, xn2, ysubw - yn2);
  117.     case 2:
  118.     mapline(xn1 + 2, ysubw - yn1 + 2, xn2 + 2, ysubw - yn2 + 2);
  119.     case 1:
  120.     default:
  121.     mapline(xn1 + 1, ysubw - yn1 + 1, xn2 + 1, ysubw - yn2 + 1);
  122.     }
  123. }
  124.  
  125. /*----------------------------------------------------------------------*\
  126. * plD_polyline_iff()
  127. *
  128. * Draw a polyline in the current color.
  129. \*----------------------------------------------------------------------*/
  130.  
  131. void 
  132. plD_polyline_iff (PLStream *pls, short *xa, short *ya, PLINT npts)
  133. {
  134.     PLINT i;
  135.  
  136.     for (i=0; i<npts-1; i++) 
  137.       plD_line_iff( pls, xa[i], ya[i], xa[i+1], ya[i+1] );
  138. }
  139.  
  140. /*----------------------------------------------------------------------*\
  141. * plD_eop_iff()
  142. *
  143. * End of page. 
  144. * Here need to close file since only 1 page/file is allowed (for now).
  145. \*----------------------------------------------------------------------*/
  146.  
  147. void 
  148. plD_eop_iff(PLStream *pls)
  149. {
  150.     iffwritefile((PLINT) pls->xdpi, (PLINT) pls->ydpi, pls->OutFile);
  151.     fclose(pls->OutFile);
  152. }
  153.  
  154. /*----------------------------------------------------------------------*\
  155. * plD_bop_iff()
  156. *
  157. * Set up for the next page.  
  158. * Advance to next family file if necessary (file output).
  159. * Here need to open a new file since only 1 page/file is allowed (for now).
  160. \*----------------------------------------------------------------------*/
  161.  
  162. void 
  163. plD_bop_iff(PLStream *pls)
  164. {
  165.     pls->page++;
  166.     mapclear();
  167.     plOpenFile(pls);
  168. }
  169.  
  170. /*----------------------------------------------------------------------*\
  171. * plD_tidy_iff()
  172. *
  173. * Close graphics file or otherwise clean up.
  174. \*----------------------------------------------------------------------*/
  175.  
  176. void 
  177. plD_tidy_iff(PLStream *pls)
  178. {
  179.     mapfree();
  180. }
  181.  
  182. /*----------------------------------------------------------------------*\
  183. * plD_state_iff()
  184. *
  185. * Handle change in PLStream state (color, pen width, fill attribute, etc).
  186. \*----------------------------------------------------------------------*/
  187.  
  188. void 
  189. plD_state_iff(PLStream *pls, PLINT op)
  190. {
  191.     switch (op) {
  192.  
  193.     case PLSTATE_WIDTH:
  194.     if (pls->width < 1)
  195.         pls->width = 1;
  196.     else if (pls->width > 3)
  197.         pls->width = 3;
  198.  
  199.     break;
  200.  
  201.     case PLSTATE_COLOR0:
  202.     break;
  203.  
  204.     case PLSTATE_COLOR1:
  205.     break;
  206.     }
  207. }
  208.  
  209. /*----------------------------------------------------------------------*\
  210. * plD_esc_iff()
  211. *
  212. * Escape function.
  213. \*----------------------------------------------------------------------*/
  214.  
  215. void 
  216. plD_esc_iff(PLStream *pls, PLINT op, char *ptr)
  217. {
  218. }
  219.